package com.handpay.zztong.hp.bean;

import android.os.Parcel;
import android.text.TextUtils;

import com.handpay.framework.LuaTableUtil;
import com.handpay.zztong.hp.main.model.BannersByChannelBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import se.krka.kahlua.vm.LuaTable;

public class NewsInfo extends Banner{

	private String bannerId;
	private String bannerName;
//	private String bannerPath;
	private String bannerLink;
	private String bannerLinkType;
	private String lastUpdateTime;

	public static String ExternalHTML = "0";
	public static String InternalHTML = "1";
	public static String InternalAPP = "3";

	
	
	public NewsInfo() {
		super();
	}



	public String getBannerId() {
		return bannerId;
	}

	public void setBannerId(String bannerId) {
		this.bannerId = bannerId;
	}

	public String getBannerName() {
		return bannerName;
	}

	public void setBannerName(String bannerName) {
		this.bannerName = bannerName;
	}

	

	public String getBannerLinkType() {
		return bannerLinkType;
	}

	public void setBannerLinkType(String bannerLinkType) {
		this.bannerLinkType = bannerLinkType;
	}

	public String getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(String lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public static List<NewsInfo> getNewsLists(LuaTable luaTable, String items) {
		List<NewsInfo> infos = new ArrayList<NewsInfo>();
		
		if (!TextUtils.isEmpty(items) && TextUtils.isDigitsOnly(items)
				&& Integer.parseInt(items) > 0) {
			LuaTable list = (LuaTable) luaTable.rawget("list");
			if (list != null) {
				Vector<LuaTable> dataList = LuaTableUtil.getArray(list);
				for (LuaTable table : dataList) {
					NewsInfo info = new NewsInfo();
					String bannerId = (String) table.rawget("bannerId");
					String bannerName = (String) table.rawget("linkTitle");
					String bannerPath = (String) table.rawget("bannerPath");
					String bannerLink = (String) table.rawget("bannerLink");
					String bannerLinkType = (String) table
							.rawget("bannerLinkType");
					String lastUpdateTime = (String) table
							.rawget("lastUpdateTime");
					info.setBannerId(bannerId);
					info.setBannerName(bannerName);
					info.setCoverUrl(bannerPath);
					info.setContentUrl(bannerLink);
					info.setBannerLinkType(bannerLinkType);
					info.setLastUpdateTime(lastUpdateTime);
					infos.add(info);
				}
			}
		}
		return infos;
	}
	
	public static NewsInfo[] getNewListsArray(BannersByChannelBean bean, String items){
		NewsInfo[] news=null;
		if (!TextUtils.isEmpty(items) && TextUtils.isDigitsOnly(items)
				&& Integer.parseInt(items) > 0) {
			List<BannersByChannelBean.ListBean> list =  bean.getList();
			if (list != null) {

				news =new NewsInfo[list.size()];
				for (int i=0;i<list.size();i++) {
					NewsInfo info = new NewsInfo();
					String bannerId =  list.get(i).getBannerId();
					String bannerName =  list.get(i).getLinkTitle();
					String bannerPath = list.get(i).getBannerPath();
					String bannerLink = list.get(i).getBannerLink();
					String bannerLinkType = list.get(i).getBannerLinkType();
					String lastUpdateTime = list.get(i).getLastUpdateTime();
					info.setBannerId(bannerId);
					info.setBannerName(bannerName);
					info.setCoverUrl(bannerPath);
					info.setContentUrl(bannerLink);
					info.setBannerLinkType(bannerLinkType);
					info.setLastUpdateTime(lastUpdateTime);
					news[i]=info;
				}
			}
		}
		return news;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		super.writeToParcel(dest, flags);
		dest.writeString(this.bannerId);
		dest.writeString(this.bannerName);
		dest.writeString(this.bannerLinkType);
		dest.writeString(this.lastUpdateTime);
	}

	protected NewsInfo(Parcel in) {
		super(in);
		this.bannerId = in.readString();
		this.bannerName = in.readString();
		this.bannerLinkType = in.readString();
		this.lastUpdateTime = in.readString();
	}

	public static final Creator<NewsInfo> CREATOR = new Creator<NewsInfo>() {
		@Override
		public NewsInfo createFromParcel(Parcel source) {
			return new NewsInfo(source);
		}

		@Override
		public NewsInfo[] newArray(int size) {
			return new NewsInfo[size];
		}
	};
}